#!/bin/bash
#===================================================================================
# FILE: tint2-session
# DESCRIPTION: manage tint2 processes for start, restart or stop all tint2 instances
# AUTHOR: Leonardo Marco
# VERSION: 1.0
# CREATED: 2020.04.09
# LICENSE: GNU General Public License v3.0
#===================================================================================

tints_path="$HOME/.config/tint2/"


#=== FUNCTION ======================================================================
# NAME: stop
# DESCRIPTION: stop all tint2 process
#===================================================================================
function stop() {
	killall tint2
	killall -9 tint2
}


#=== FUNCTION ======================================================================
# NAME: start
# DESCRIPTION: load each .tint file in user tint path
#===================================================================================
function start() {
	local IFS=$'\n'
	for f in $(ls "$tints_path"/*.tint2rc); do
		(setsid tint2 -c "$f" &)
	done 
}


# EXEC ACTION ACCORDING $1
case "${1,,}" in
	""|start|restart)
		stop
		start		
	;;
	stop)	
		stop	
	;;
	*)	
		echo "Usage: tint2-session [start|stop|restart]"
	;;
esac
